﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Rechargeable.Web.Pages;
using Rechargeable.Products;
using Rechargeable.Products.Dtos;

namespace Rechargeable.Web.Pages.Products.Prices
{
    public class CreateModalModel : RechargeablePageModel
    {

        [BindProperty]
        public CreateUpdateProductPriceDto CreateUpdateProductPriceDto { get; set; }

        [BindProperty(SupportsGet = true)]
        public Guid ProductId { get; set; }

        private readonly IProductPriceAppService _productPriceAppService;

        public CreateModalModel(IProductPriceAppService productPriceAppService)
        {
            _productPriceAppService = productPriceAppService;
        }

        public void OnGet()
        {
            if(CreateUpdateProductPriceDto==null)
            {
                CreateUpdateProductPriceDto = new CreateUpdateProductPriceDto();
            }
            CreateUpdateProductPriceDto.ProductId = ProductId;
        }

        public async Task<IActionResult> OnPostAsync()
        {
            //CreateUpdateProductPriceDto.ProductId = ProductId;
            await _productPriceAppService.CreateAsync(CreateUpdateProductPriceDto);
            return NoContent();
        }
    }
}